Q2 With a given number n program to generate dictionary that contains(i,i*i) such that number between 1 and n.l=[] for i in range(2000,2100): if(i%7==0)and(i%5!=0): l.append(str(i)) print(l) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== ['2002', '2009', '2016', '2023', '2037', '2044', '2051', '2058', '2072', '2079', '2086', '2093']
Q3.Program that accept a sentence and calculate the number of letter and digit.n=int(input("enter number")) d=dict() for i in range(1,n+1): d[i]=i*i print(d) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== enter number5 {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
Q4.Program that accept a sentence and calculate number of uppercase and lowercase letters.i=input("enter string") letter=0 digit=0 for c in i: if c.isdigit(): digit+=1 elif c.isalpha(): letter+=1 else: pass print(digit) print(letter) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== enter stringaba123 3 3
Q5.Program to find factorial and store result in dictionary.s=input("enter sentence"); ucase=0 lcase=0 for c in s: if c.isupper(): ucase+=1 elif c.islower(): lcase+=1 else: pass print('uppercase',ucase) print('lowercase',lcase) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== enter sentenceAbC uppercase 2 lowercase 1
def fact(x): if x==0: return 1 else: return(x*fact(x-1)) x=int(input("enter number")) d=dict() d[x]=fact(x) print(d) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== enter number5 {5: 120}
0 Comments